package service

import (
	"context"
	"fmt"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"mini-gde/client"
	"mini-gde/model"
)

func ListPods() []model.Pod {
	k8spods, err := client.Clientset.CoreV1().Pods("kube-system").List(context.TODO(), metav1.ListOptions{})
	if err != nil {
		fmt.Println("err ")
	}

	pods := []model.Pod{}
	for _, pod := range k8spods.Items {
		fmt.Println(pod.Name)
		tmp := model.Pod{
			Name:      pod.ObjectMeta.Name,
			Namespace: pod.ObjectMeta.Namespace,
			Uid:       string(pod.ObjectMeta.UID),
		}
		pods = append(pods, tmp)
	}
	return pods
}
